package com.wenhui.schoolyardinfo.firstpage.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wenhui.schoolyardinfo.R;
import com.wenhui.schoolyardinfo.callback.RcvOnItemItemViewClickListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/6/14 11:01
 * introduce :
 */

public class SceneryAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<String> sceneryList = new ArrayList<>();

    public SceneryAdapter(Context context) {
        this.context = context;
    }

    public SceneryAdapter(Context context, List<String> sceneryList) {
        this.context = context;
        this.sceneryList = sceneryList;
    }

    public void clearData() {
        sceneryList.clear();
        notifyDataSetChanged();
    }

    public void addAllData(List<String> sceneryList) {
        this.sceneryList.addAll(sceneryList);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_scenery, null);
        return new ContentHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ContentHolder) {
            ContentHolder contentHolder = (ContentHolder) holder;
            //加载风景
            Glide.with(context).load(sceneryList.get(position)).into(contentHolder.imvScenery);
        }
    }

    @Override
    public int getItemCount() {
        return sceneryList.size();
    }


    protected class ContentHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        @BindView(R.id.imv_scenery)
        ImageView imvScenery;

        public ContentHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);


        }

        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.layout_feeling:

                    break;
                default:
                    break;
            }
        }
    }

    private RcvOnItemItemViewClickListener rcvOnItemItemViewClickListener;

    public void setRcvOnItemItemViewClickListener(RcvOnItemItemViewClickListener rcvOnItemItemViewClickListener) {
        this.rcvOnItemItemViewClickListener = rcvOnItemItemViewClickListener;
    }
}
